package com.lf.web.service;

import com.lf.data.Cluster;
import com.lf.data.search.Query;
import com.lf.web.service.system.config.Config;
import com.lf.web.service.system.config.ConfigDAO;
import com.lf.web.service.system.menu.MenuDAO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class IndexService extends ServiceSupport {
    private MenuDAO menudao = null;
    private ConfigDAO configdao;
    private Config system = new Config();

    public void setMenudao(MenuDAO menudao) {
        this.menudao = menudao;
    }

    public void setConfigdao(ConfigDAO configdao) {
        this.configdao = configdao;
    }

    public String execute() {
        List<Cluster> menu0 = menudao.findByParentid(null);
        List<Cluster> menu1;
        if (!menu0.isEmpty()) {
            Cluster mm = menu0.get(0);
            menu1 = menudao.findByParentid(mm.getId());
        } else {
            menu1 = new ArrayList();
        }
        Query query = new Query();
        query.eq(system.NAME, "system");
        system.putAll(configdao.findOne(query));
        context.put("menu0", menu0);
        context.put("menu1", menu1);
        context.put("system", system);
        return "success";
    }
}
